<template>
	<view class="pages">
		<view class="label">
			<view class="label-item" :class="labelActiveIndex==0?'label-item-color':'label-item-color-default'" @click="labelActvie(0)">未使用</view>
			<view class="label-item" :class="labelActiveIndex==1?'label-item-color':'label-item-color-default'" @click="labelActvie(1)">已使用</view>
		</view>
		<view class="code-list">
			<view class="code-item" v-for="(item,index) in list" :key="index" @click="goPages('/pages/users/qrcodeDetail/qrcodeDetail?id='+item.id)">
				<view class="code-item-a">
					<image src="/static/images/qrcode01.png" mode=""></image>
					<view>{{item.name}}</view>
				</view>
				<view class="code-item-b">购买时间:{{item.created_at}}</view>
			</view>
			
			<view class="noCart" v-if="list.length == 0">
				<view class="pictrue">
					<image src="/static/images/noInvoice.png"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { qrcodelist } from '@/api/user.js';
	export default {
		data() {
			return {
				labelActiveIndex: 0,
				list: [],
				page: 1,
				limit: 20
			}
		},
		onLoad() {
			this.qrcode();
		},
		methods: {
			labelActvie(num){
				let self = this;
				if(self.labelActiveIndex != num){
					self.list = [];
					self.page = 1;
					self.labelActiveIndex = num;
					self.qrcode()
				}
			},
			goPages(url){
				uni.navigateTo({
					url: url
				})
			},
			qrcode(){
				let self = this;
				qrcodelist({
					status: self.labelActiveIndex,
					page: self.page,
					limit: self.limit
				}).then(res => {
					// console.log('请求成功',res);
					self.list = self.list.concat(res.data);
					if(res.data.length != 0 ){
						self.page++;
					}else{
						
					}
				}).catch(err => {
					console.log('请求失败',err);
				})
			}
		},
		onReachBottom() {
			let self = this;
			self.qrcode()
		}
	}
</script>

<style lang="less">
.pages{
	min-height: 100vh;
	background-color: #f2f2f2;
	padding-top: 90rpx;
	.label{
		display: flex;
		border-top: 2rpx solid #f8f8f8;
		background-color: #FFFFFF;
		width: 100%;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 99;
		.label-item{
			width: 50%;
			font-size: 28rpx;
			line-height: 90rpx;
			line-height: #DD4134;
			text-align: center;
			font-weight: 600;
		}
		.label-item-color-default{
			color: #000000;
		}
		.label-item-color{
			color: #DD4134;
			position: relative;
		}
		.label-item-color::after{
			content: "";
			width: 100%;
			height: 4rpx;
			background-color: #DD4134;
			position: absolute;
			left: 0;
			bottom: 0;
			
		}
	}
	
	.code-list{
		padding: 24rpx 20rpx;
		.code-item{
			padding: 30rpx;
			background-color: #FFFFFF;
			border-radius: 10rpx;
			margin-bottom: 20rpx;
			.code-item-a{
				display: flex;
				image{
					display: block;
					width: 35rpx;
					height: 35rpx;
				}
				view{
					width: 600rpx;
					font-size: 30rpx;
					line-height: 35rpx;
					color: #020202;
					font-weight: 600;
					padding-left: 15rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}
			}
			.code-item-b{
				font-size: 22rpx;
				color: #A7A7A8;
				line-height: 30rpx;
				padding-top: 20rpx;
				padding-left: 50rpx;
			}
		}
	}

	.noCart {
		margin-top: 171rpx;
		padding-top: 0.1rpx;
		.pictrue {
			width: 414rpx;
			height: 336rpx;
			margin: 78rpx auto 56rpx auto;
			image {
				width: 100%;
				height: 100%;
			}
		}
	}
}
</style>
